<?php
if(!defined('ADMINPX') || !defined('ADMIN')) {
	exit('Access Denied');
}
$act=$_GET['act'];
if($act=='ok'){
   if(!$_POST[adminpost]){
	   echo"提交出错<br/>";
   }else{
   	 $_POST['smtp_password']=authcode($_POST['smtp_password'],'ok','Bingz');
	   Bingz_config('email_smtp_sezhi',$_POST['email_smtp_sezhi'],'post');
	   Bingz_config('email_smtp_servers',$_POST['smtp_servers'],'post');
	   Bingz_config('email_smtp_username',$_POST['smtp_username'],'post');
	   Bingz_config('email_smtp_password',$_POST['smtp_password'],'post');
	   Bingz_config('email_smtp_from',$_POST['smtp_from'],'post');
	   Bingz_config('email_smtp_port',$_POST['smtp_port'],'post');
	   Bingz_config('email_smtp_fromname',$_POST['email_smtp_fromname'],'post');
	   Bingz_config('email_smtp_fromyh',$_POST['email_smtp_fromyh'],'post');
     echo"提交成功<br/>";
	 }
   echo "正在自动返回.......<br/><a href=\"admin.php?action=email\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=email'>";
}elseif($act=='postok'){
   if(!$_POST[adminpost]){
	   echo"提交出错<br/>";
   }elseif(Bingz_config('email_smtp_sezhi') == '0' ){
	   echo"请先开启邮件发送<br/>";
   }elseif(!$_POST[check_smtp] or !$_POST[title] or !$_POST[name] ){
	   echo"不能为空<br/>";
   }elseif(!preg_match("/^([0-9A-Za-z\-\_])+@([0-9a-zA-Z\.])+([0-9A-Za-z\.])+$/",$_POST[check_smtp])){
   	 echo"邮箱格式错误<br/>";
   }elseif($smsots=Bingz_email_smtp_post($_POST['check_smtp'],$_POST['title'],$_POST['name'])){
     if($smsots == '1'){
        echo"发送成功<br/>";
     }else{
        echo"发送失败！<br/>提示：$smsots <br/>";
	   }
	 }
   echo "正在自动返回.......<br/><a href=\"admin.php?action=email\">请手动返回</a><br/><meta http-equiv=refresh content='30;url=admin.php?action=email'>";
}elseif($act=='post'){
	$email=$_GET['email'];
echo <<<end
<a href="admin.php?action=email">返回邮件配置</a><br/>
<div class="admin">==发送邮件==<br/></div>
	<form  method="post" action="admin.php?action=email&act=postok">
	收件人地址:<br/>
	<input class="text" type="text" name="check_smtp"  value="$email" />
<br/>
  邮件标题:<br/>
	<input class="text" type="text" name="title" placeholder="请输标题" /><br/>
	邮件内容:<br/>
  <textarea class="textarea" type="text" name="name" placeholder="请输内容" ></textarea><br/>
	<input class="submit" type="submit" name="adminpost" value="立即发送" />
</form>
	<br/>
end;
}elseif($act=='pzok'){
   if(!$_POST[adminpost]){
	   echo"提交出错<br/>";
   }else{
	   Bingz_config('email_set_reg',$_POST['email_set_reg'],'post');
	   Bingz_config('email_set_reg_title',$_POST['email_set_reg_title'],'post');
	   Bingz_config('email_set_reg_body',$_POST['email_set_reg_body'],'post');
	   Bingz_config('email_set_editpwd',$_POST['email_set_editpwd'],'post');
	   Bingz_config('email_set_editpwd_title',$_POST['email_set_editpwd_title'],'post');
	   Bingz_config('email_set_editpwd_body',$_POST['email_set_editpwd_body'],'post');
	   Bingz_config('email_set_renzheng',$_POST['email_set_renzheng'],'post');
	   Bingz_config('email_set_renzheng_title',$_POST['email_set_renzheng_title'],'post');
	   Bingz_config('email_set_renzheng_body',$_POST['email_set_renzheng_body'],'post');
	   Bingz_config('email_set_payment',$_POST['email_set_payment'],'post');
	   Bingz_config('email_set_payment_title',$_POST['email_set_payment_title'],'post');
	   Bingz_config('email_set_payment_body',$_POST['email_set_payment_body'],'post');
     echo"提交成功<br/>";
	 }
   echo "正在自动返回.......<br/><a href=\"admin.php?action=email\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=email'>";
}else{
if(Bingz_config('email_smtp_sezhi') == '1'){$email_smtp_sezhi='selected="selected"';}else{$email_smtp_sezhia='selected="selected"';}
$smtp_servers=Bingz_config('email_smtp_servers');
$smtp_username=Bingz_config('email_smtp_username');
$smtp_password=authcode(Bingz_config('email_smtp_password'),'DECODE','Bingz');
$smtp_from=Bingz_config('email_smtp_from');
$smtp_port=Bingz_config('email_smtp_port');
$email_smtp_fromname=Bingz_config('email_smtp_fromname');
$email_smtp_fromyh=Bingz_config('email_smtp_fromyh');

if(Bingz_config('email_set_reg') == '1'){$email_set_reg='selected="selected"';}else{$email_set_rega='selected="selected"';}
$email_set_reg_title=Bingz_config('email_set_reg_title');
$email_set_reg_body=Bingz_config('email_set_reg_body');
if(Bingz_config('email_set_editpwd') == '1'){$email_set_editpwd='selected="selected"';}else{$email_set_editpwda='selected="selected"';}
$email_set_editpwd_title=Bingz_config('email_set_editpwd_title');
$email_set_editpwd_body=Bingz_config('email_set_editpwd_body');
if(Bingz_config('email_set_renzheng') == '1'){$email_set_renzheng='selected="selected"';}else{$email_set_renzhenga='selected="selected"';}
$email_set_renzheng_title=Bingz_config('email_set_renzheng_title');
$email_set_renzheng_body=Bingz_config('email_set_renzheng_body');
if(Bingz_config('email_set_payment') == '1'){$email_set_payment='selected="selected"';}else{$email_set_paymenta='selected="selected"';}
$email_set_payment_title=Bingz_config('email_set_payment_title');
$email_set_payment_body=Bingz_config('email_set_payment_body');

echo <<<end
<div class="admin">==邮件配置==<br/></div>
	<form  method="post" action="admin.php?action=email&act=ok">
	<b>1.通过连接 SMTP 服务器发送邮件</b><br/>
  邮件发送:<select name="email_smtp_sezhi">
<option value="1" $email_smtp_sezhi >开启</option>
<option value="0" $email_smtp_sezhia >关闭</option>
</select><br/>
	SMTP服务器地址:(如：smtp.qq.com)<br/>
	<input class="ipt-text" type="text" name="smtp_servers" value="$smtp_servers" />
<br/>
	SMTP服务帐户名:<br/>
	<input class="ipt-text" type="text" name="smtp_username" value="$smtp_username" />
<br/>
	SMTP服务密码:<br/>
	<input class="ipt-pass" type="password" name="smtp_password" value="$smtp_password" />
<br/>
	发信人邮件地址:<br/>
	<input class="ipt-text" type="text" name="smtp_from" value="$smtp_from" />
<br/>
	发信人名称:<br/>
	<input class="ipt-text" type="text" name="email_smtp_fromname" value="$email_smtp_fromname" />
<br/>
	收信人名称:<br/>
	<input class="ipt-text" type="text" name="email_smtp_fromyh" value="$email_smtp_fromyh" />
<br/>
	SMTP 端口:(默认25)<br/>
	<input class="ipt-text" type="text" name="smtp_port" value="$smtp_port" />
<br/>
	<input class="submit" type="submit" name="adminpost" value="提交修改" />
</form>  <a href="admin.php?action=email&act=post">发送邮件</a><br/>
	<br/>

	<b>2.发送规则</b><br/>
	<form  method="post" action="admin.php?action=email&act=pzok">
	(1)<u>注册会员</u>:<select name="email_set_reg">
<option value="1" $email_set_reg >通知</option>
<option value="0" $email_set_rega >不通知</option>
</select><br/>
	注册会员成功后发送邮件通知<br/>
  邮件标题模版:<br/>
	<input class="" type="text" name="email_set_reg_title" value="$email_set_reg_title" /><br/>
	邮件内容模版:<br/>
	<textarea class="textarea" name="email_set_reg_body"  >$email_set_reg_body</textarea>
<br/>
	
	(2)<u>修改密码</u>:<select name="email_set_editpwd">
<option value="1" $email_set_editpwd >通知</option>
<option value="0" $email_set_editpwda >不通知</option>
</select>
<br/>
	会员修改密码后是否邮件通知<br/>
  邮件标题模版:<br/>
	<input class="" type="text" name="email_set_editpwd_title" value="$email_set_editpwd_title" /><br/>
	邮件内容模版:<br/>
	<textarea class="textarea" name="email_set_editpwd_body" >$email_set_editpwd_body</textarea>
<br/>
	
	(3)<u>邮箱认证</u>:<select name="email_set_renzheng">
<option value="1" $email_set_renzheng >通知</option>
<option value="0" $email_set_renzhenga >不通知</option>
</select>
<br/>
	开通注册邮件验证的认证通知<br/>
  邮件标题模版:<br/>
	<input class="" type="text" name="email_set_renzheng_title" value="$email_set_renzheng_title" /><br/>
	邮件内容模版:<br/>
	<textarea class="textarea" name="email_set_renzheng_body" >$email_set_renzheng_body</textarea>
<br/>
	(4)<u>付款成功</u>:<select name="email_set_payment">
<option value="1" $email_set_payment >通知</option>
<option value="0" $email_set_paymenta >不通知</option>
</select>
<br/>
	会员订单付款完成是否邮件通知<br/>
  邮件标题模版:<br/>
	<input class="" type="text" name="email_set_payment_title" value="$email_set_payment_title" /><br/>
	邮件内容模版:<br/>
	<textarea class="textarea" name="email_set_payment_body" >$email_set_payment_body</textarea>
<br/>
	<input class="submit" type="submit" name="adminpost" value="提交修改" />
</form>
	<br/>
end;
}
?>